

function LoadModule(cTarget) {
    var mdl = { title: '', id: '', url: '', htm: '' };
    try {
        DoGetModule(mdl, cTarget);
    }
    catch (e) {
        alert('errorr' + e);
    }
};
function DoGetModule(mdl, cTarget) {
    var module = Ext.get(cTarget);
    

    if (module === null) {

      
        Ext.Ajax.request(
	{
	    url: "./home.mvc/getModule",
	    params: {
	        UserID: 'Admin',
	        ModuleID: cTarget                      // parameter untuk url yang dituju (fungsi didalam controller)
	    },
	    success: function(o) {
	        var cst = Ext.decode(o.responseText);


	        mdl.title = cst.title;
	        mdl.id = cst.id;
	        mdl.url = cst.url;
	        mdl.htm = cst.htm;
	      
	        CurrentPage.id = mdl.id;
	      
		
	        LoadScripts(mdl.htm);
	        mainPage.doLayout();

	 

	    }

	});
    }
    else {
        mainPage.setActiveTab(cTarget);
    }
}; 

function LoadScripts(records) {

    var i;

    for (var i = 0; i < records.length; i++) {
        var x = records[i];
        dhtmlLoadScript(x.Script)
    };

};

function DoProcess(mdl, cTarget) {

   

        // ajax digunakan untuk meminta hak akses dari server untuk modul yg di request
        Ext.Ajax.request({
            url: "./Module.mvc/ExecProc",
            params: {
                UserID: 'Admin',
                ModuleID: cTarget                      // parameter untuk url yang dituju (fungsi didalam controller)
            },
            success: function(o) {
                var cst = Ext.decode(o.responseText);


                mdl.title = cst.title;
                mdl.id = cst.id;
                mdl.url = cst.url;
                mdl.htm = cst.htm;


                mainPage.add(mddata);
                mainPage.setActiveTab(mdl.id);



            }

        });
   
    //alert(ss);
    return mdl;
}

function dhtmlLoadScript(url) {
    var e = document.createElement("script");
    e.src = url;
    e.type = "text/javascript";

    document.getElementsByTagName("head")[0].appendChild(e);
}



function GetPanel(mdl) {
    var cHtm = '<div id="home" align="center">';
    cHtm += mdl.htm;
    cHtm += '</div>';
    var TabAng = new Ext.Panel({
        id: mdl.id,
        closable: true,
        title: mdl.title,
        region: 'center', // this is what makes this panel into a region within the containing layout
        layout: 'fit',
        margins: '0 5 5 0',
        border: false,
        deferredRender: false,
        //html: cHtm,
        viewConfig: {
            forceFit: true
        }
    });
 
    return TabAng;
};

function LoadReport(cTarget) {
    var mdl = { title: '', id: '', url: '', htm: '', havedialog: false };

    // ajax digunakan untuk meminta hak akses dari server untuk modul yg di request
    Ext.Ajax.request(
		{
		    url: "./Home.mvc/getReport",
		    params: {
		        UserID: 'Admin',
		        ModuleID: cTarget                      // parameter untuk url yang dituju (fungsi didalam controller)
		    },
		    success: function(o) {
		        var cst = Ext.decode(o.responseText);
		        mdl = cst;
		      
	
		        if (mdl.havedialog === true) {
					
		        
		            CurrentPage.id = mdl.id;
		          
		            LoadScripts(mdl.htm);
		            mainPage.doLayout();
		        }
		        else {

		            ShowReport('', mdl.id, '');
		        }
		    
		    }

		});
};

function ShowReport(cUser, cTarget, cParams) {
    var mdl = { title: '', id: '', url: '', htm: '' };
    // ajax digunakan untuk meminta hak akses dari server untuk modul yg di request

    Ext.Ajax.request({
        url: "./Module.mvc/ExecReport",
        params: {
            UserID: 'Admin',
            ModuleID: cTarget,    // parameter untuk url yang dituju (fungsi didalam controller)
            Params: cParams    // parameter untuk url yang dituju (fungsi didalam controller)
        },
        success: function(o) {
            var cst = Ext.decode(o.responseText);


            mdl = cst;
            
              if (cst.success === true)
            {
                window.open('viewPdf.aspx?title=' + mdl.title + '&pdf=' + mdl.url, '_blank', 'location=0,resizable=1',false);
            }
            else
            {
               Ext.MessageBox.show
	            (
		            {
		               title: cst.title,
		               msg:cst.msg,
		               buttons: Ext.MessageBox.OK,
		               icon: Ext.MessageBox.INFO
		            }
	            );
            };

            
         
        }

    });

};

function ShowWindowReport(mdl) {
 
        window.open(mdl.url, mdl.title, "fullscreen=yes");
}

function GetPanelFrame(mdl) {
    var TabAng = new Ext.ux.IFrameComponent({
        //var TabAng = new Ext.Panel({
        id: mdl.id,
        shim: false,
        floating: true,
        autoLoad: false,
        closable: true,
        title: mdl.title,
        region: 'center', // this is what makes this panel into a region within the containing layout
        layout: 'fit',
        margins: '0 5 5 0',
        border: false,
        deferredRender: false,
        url: mdl.url,
        viewConfig: {
            forceFit: true
        }
    });
 
    return TabAng
};


